package com.hoshiibuy.idGenerator.consumer.controller;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hoshiibuy.idGenerator.consumer.service.UidGenService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = "获取ID接口")
public class UidRestController {
	@Autowired
	private UidGenService uidGenService;

	@RequestMapping(value = "/getuuId", method = { RequestMethod.GET, RequestMethod.POST })
	@ApiOperation(value = "获取一个ID")
	public String getuuId() {
		return String.valueOf(uidGenService.getUid());
	}

	@RequestMapping(value = "/getuuIdSet", method = { RequestMethod.GET, RequestMethod.POST })
	@ApiOperation(value = "获取多个ID")
	@ApiImplicitParam(name = "count", value = "要获取的ID数量", example = "10")
	public Set<String> getuuIdSet(@RequestParam int count) {
		// 限制单次获取的数量
		if (count > 100) {
			return null;
		}
		return uidGenService.getUidList(count);
	}
}
